package com.wiselink.fastbox.orderplacement;

import com.wiselink.exception.FastBoxException;
import com.wiselink.fastbox.FastBoxBaseAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

public class Main {
    private static final Logger log = LoggerFactory.getLogger(com.wiselink.common.Main.class);

    public static void main(String[] args) {
        FastBoxBaseAPI.init(FastBoxBaseAPI.Env.QA.name(),
                "",
                "",
                new FastBoxBaseAPI.ShopInfo("", "", "", ""));

        String orderNo = UUID.randomUUID().toString().replaceAll("-", "");
        Map<String, String> map = new HashMap<>();
        map.put("orderNo", orderNo);

        log.debug("=======调用订单注册=======");
        OrderRegistration orderRegistration = new OrderRegistration(Collections.singletonList(TestData.getOrderRegistrationBO(orderNo)));
        try {
            orderRegistration.post();
            List<OrderRegistration.ResultVO> orderRegistrationResult = orderRegistration.getResult();
        } catch (FastBoxException e) {
            log.error("订单注册失败: {}", e.getMessage(), e);
            // TODO 将失败信息记录在订单中，方便异常排查
        }

        log.debug("=======调用配送说明=======");
        DeliveryInstruction deliveryInstruction = new DeliveryInstruction(map);
        try {
            deliveryInstruction.post();
            List<DeliveryInstruction.ResultVO> deliveryInstructionResult = deliveryInstruction.getResult();
        } catch (FastBoxException e) {
            log.error("配送说明失败: {}", e.getMessage(), e);
            // TODO 将失败信息记录在订单中，方便异常排查
        }

        log.debug("=======调用订单查询=======");
        OrderInformationQuery orderInformationQuery = new OrderInformationQuery(orderNo);
        orderInformationQuery.get();
        orderInformationQuery.getResult();

        log.debug("=======调用轨迹查询=======");
        ShipmentTracking shipmentTracking = new ShipmentTracking(orderNo);
        shipmentTracking.get();
        shipmentTracking.getResult();
    }
}